package alkaid.eis.sys.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.NamedAttributeNode;
import javax.persistence.NamedEntityGraph;
import javax.persistence.NamedEntityGraphs;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.springframework.beans.BeanUtils;

import alkaid.eis.sys.core.AbstractBaseEntity;
import lombok.Getter;
import lombok.Setter;

/**
 * 字典
 * 
 * @author Lucky Yang
 * @since 0.0.1
 */
@Entity
@Getter
@Setter
@Table(name = "eis_sys_dict")
@NamedEntityGraphs({
                @NamedEntityGraph(name = "Dict.details", attributeNodes = {
                                @NamedAttributeNode("details")
                })
})
public class Dict extends AbstractBaseEntity implements Serializable {
        /** 代码 */
        @Column(updatable = false, unique = true)
        private String code;

        /** 描述 */
        private String description;

        @OneToMany(mappedBy = "dict", cascade = { CascadeType.PERSIST, CascadeType.REMOVE })
        private List<DictDetail> details = new ArrayList<>();

        public Dict() {
        }

        public Dict(String code) {
                this.code = code;
        }

        
        public Dict(String code, String description) {
                this.code = code;
                this.description = description;
        }

        public void copy(Dict source) {
                BeanUtils.copyProperties(source, this, "id,details".split(","));
        }
}
